package com.imooc.core.utils;

//import com.gxguifan.sugar.entity.User;
import org.apache.log4j.Logger;
import org.springframework.util.StringUtils;

import javax.servlet.http.HttpServletRequest;


/**
 * HttpServletResponse帮助类
 * 
 * @author lujianzhong
 * 
 */
public final class RequestUtils {
	public static final Logger logger = Logger.getLogger(RequestUtils.class);

	/**
	 * 获取网站项目的完整域名
	 * 
	 * 网络路径:http://192.168.0.176:8080/WapCms
	 * 转换后:http://192.168.0.176:8080/WapCms
	 * @param request
	 * @return
	 */
	public static String getWebappsDomain(HttpServletRequest request) {
		String result = request.getScheme() + "://" + request.getServerName()
				+ ":" + request.getServerPort()
				+ request.getContextPath();
		result = StringUtils.replace(result, "\\", "/");
		//logger.info("获取网站项目的完整域名:" + result);
		return result;
	}
	
	/**
	 * 获取网站项目所在硬盘的绝对路径
	 * 绝对路径D:\Program Files\apache-tomcat-6.0.20\webapps\WapCms\
	 * 再转换成D:/Program Files/apache-tomcat-6.0.20/webapps/WapCms
	 * @param request 
	 * @return
	 */
	public static String getWebappsAbsoluPath(HttpServletRequest request) {
		String result = request.getSession().getServletContext().getRealPath("/");
		result = result.substring(0, result.length() - 1);
		result = StringUtils.replace(result, "\\", "/");
		result += "";
		//logger.info("获取网站项目所在硬盘的绝对路径:" + result);
		return result;
	}

	/**
	 * 获取当前登录的用户实体
	 * @param request
	 * @return
	 */
//	public static User getCurrentLonginedUser(HttpServletRequest request) {
//		User u = (User) request.getSession().getAttribute("SESSION_USER");
//		return u;
//	}
}
